<template>
  <div class="app-container">
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="applyUserName"
        label="贷款申请人"
        width="180">
      </el-table-column>
      <el-table-column
        prop="loadAmount"
        label="贷款申请额度"
        width="180">
      </el-table-column>
      <el-table-column
        prop="loadPurpose"
        label="贷款申请用途">
      </el-table-column>
      <el-table-column
        prop="loadLimitDate"
        label="贷款期限">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="entryInfo(scope.row)" v-show="userName == 'A01'">现场调查信息录入</el-button>
          <el-button type="primary" @click="agree(scope.row)" v-show="userName !== 'A01'">同意</el-button>
          <el-button type="warning" @click="refuse(scope.row)">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <EntryInfo ref="entryInfo"/>

  </div>
</template>
<script>
  import { queryTask, checkApply, riskCheckApply } from '@/api/loanInfo'
  import EntryInfo from './entryInfo'
  import store from '@/store'
  export default {
    components: { EntryInfo },
    data() {
      return {
        tableData: [],
        userName: ''
      }
    },

    created(){
      this.userName = store.getters.name
      let data = { userName: store.getters.name}
      queryTask(data).then(res => {
         console.log(res)
        this.tableData = res.data
      })
    },
    methods: {
      entryInfo(data){
        this.$refs['entryInfo'].dialogVisible = true
        this.$refs['entryInfo'].form.id = data.id
        this.$refs['entryInfo'].form.applyUserName = data.applyUserName
        this.$refs['entryInfo'].form.idCard = data.idCard
        this.$refs['entryInfo'].form.phone = data.phone
        this.$refs['entryInfo'].form.taskId = data.taskId
      },
      agree(data){
        // approve 0:拒绝   1:同意
        data.approve = '1'

        // 如果是风控业务人员账号，请求风控微服务
        if(this.userName === 'R01'){
          riskCheckApply(data).then(res => {
            if(res.code === 200){
              alert("提交成功")
            }
          })
          return
        }

        checkApply(data).then(res => {
          if(res.code === 200){
            alert("提交成功")
          }
        })
      },
      refuse(data){
        data.approve = '0'

        // 如果是风控业务人员账号，请求风控微服务
        if(this.userName === 'R01'){
          riskCheckApply(data).then(res => {
            if(res.code === 200){
              alert("提交成功")
            }
          })
          return
        }

        checkApply(data).then(res => {
          if(res.code === 200){
            alert("提交成功")
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
